import { Entity, Column, PrimaryGeneratedColumn, CreateDateColumn, UpdateDateColumn, ManyToMany, JoinTable } from 'typeorm';
import { Permission } from './permission.entity';

@Entity('sys_role')
export class Role {
    @PrimaryGeneratedColumn({ comment: '角色ID' })
    id: number;

    @Column({ length: 50, unique: true, comment: '角色名称' })
    roleName: string;

    @Column({ length: 50, unique: true, comment: '角色标识' })
    roleCode: string;

    @Column({ default: 0, comment: '显示顺序' })
    roleSort: number;

    @Column({ 
        type: 'tinyint',
        default: 1, 
        comment: '角色状态(1-正常, 0-禁用)' 
    })
    status: number;

    @Column({ length: 500, nullable: true, comment: '备注' })
    remark: string;

    @Column({ length: 50, nullable: true, comment: '创建者' })
    createBy: string;

    @CreateDateColumn({ comment: '创建时间' })
    createTime: Date;

    @Column({ length: 50, nullable: true, comment: '更新者' })
    updateBy: string;

    @UpdateDateColumn({ comment: '更新时间' })
    updateTime: Date;

    @Column({ 
        type: 'tinyint',
        default: 0, 
        comment: '删除标志(0-存在, 1-删除)' 
    })
    delFlag: number;

    @ManyToMany(() => Permission)
    @JoinTable({
        name: 'sys_role_permission',
        joinColumn: {
            name: 'roleId',
            referencedColumnName: 'id'
        },
        inverseJoinColumn: {
            name: 'permId',
            referencedColumnName: 'id'
        }
    })
    permissions: Permission[];
}